use "$OUTDATA/ddd-reds_withmain.dta", clear


********************************************************************************
* Sample selection
********************************************************************************

rename yearbirth yearb
gen hindu1 = (muslim == 0)
gen christian = relig == 4
replace hindu = relig == 1

cap rename dow99 dow_99

rename post dow_cohort
sum dow_99,d
drop if dow_99>=r(p99) & dow_99!=.

sort year_marriage

replace dow_99 = dow_99/1000
replace downet_99 = downet_99/1000

drop _merge
// merge with deflate data
merge m:1 year_marriage using "$OUTDATA/deflatedow"

rename year_marriage yy_1marr
keep if yy_1marr >= 1975

gen dowTreat = dow_cohort*hindu1

gen yearb1975 = (yearb<1975)
replace  yearb1975 =. if yearb == .

// zero dowry dummy
gen zdow=dow_99==0
replace zdow=. if dow_99==.

// missing dowry indicator
gen missingdow = dow_99 == .

// Karnataka and Maharashtra had issues with missing dowry data (see appendix of Chiplunkar and Weaver)
// In Maharashtra surveyors correctly recorded if dowry was not paid (value of zero), but in nearly all cases where it was paid, they did not record the value. As a result, they recorded a missing value for the dowry payment field in that situation.
// In Karnataka cases where the respondents did not pay dowry were recorded as missing values.

replace missingdow = . if state == 10 | state == 7

gen scstbc = (caste_sc == 1 | caste_st == 1 | caste_obc == 1)
gen rural = 1
label var dow_cohort "Post"
label var hindu1 "Non-Muslim"

* Average dowries

bysort yy_1m: egen dow99_avg = mean(dow_99)
bysort yy_1m: egen downet99_avg = mean(downet_99)
bysort yy_1m: egen missing_avg = mean(missingdow)
bysort yy_1m: egen zdow_avg = mean(zdow)


** Create dummies for States 
** treated by Hindu Sucession Act (HSA)
 
gen hsa_year = 1976 * (state == 8) + 1986 * (state == 1) + 1989 * (state == 14) + 1994 * (state == 7 | state == 10) + 2005 * (state != 8 & state != 1 & state != 14 & state != 7 & state != 10) 
gen hsa_cohort = (hsa_year <= yy_1marr) 
replace hsa_cohort = . if yy_1marr == . | hsa_year == . 
gen hsa_state = (state == 8 | state == 1 | state == 14 | state == 7 | state == 10) 

gen dowearly_year = 1976 * (state == 2 | state == 12 | state == 4 | state == 5 | state == 16 | state == 11) + 1986 * (state != 2 | state != 12 | state != 4 | state != 5 | state != 16 | state != 11) 
gen dowearly_cohort = (dowearly_year <= yy_1marr) 
replace dowearly_cohort = . if yy_1marr == . | dowearly_year == . 
gen dowearly_state = (state == 2 | state == 12 | state == 4 | state == 5 | state == 16 | state == 11) 

label var hsa_cohort "HSA Amended"
label var dowearly_cohort "Early Amended"
label var hsa_state "HSA State"

gen dataproblem = (state == 1 | state == 3 | state == 10 | state == 11 | state == 14 )

gen marr_age = yy_1m - yearb
gen age = 1999 - yearb

gen dow_99_asinh = asinh(dow_99)

* Labels

label var dow_99 "Dowry"
label var downet_99 "Net Dowry"
label var zdow "No Dowry"

label var scstbc "SC/ST/OBC"
label var rural "Rural"
label var muslim "Muslim"
label var christian "Christian"
label var hindu "Hindu"
label var primary "Primary School"
label var secondary "Secondary School"  
label var primary_spouse "Husband Primary School"
label var secondary_spouse "Husband Secondary School"
label var years_schooling "Years of Schooling"
label var years_schooling_spouse "Husband Years of Schooling"
label var owns_land "Land Ownership"  
label var hh_members "Household Size"  
label var marr_age "Age at Marriage"  

save "$OUTDATA/REDS_sample.dta", replace 
